<!DOCTYPE html>
<html>
  <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title><?php echo isset($title) ? $title : '';?></title>
      <!-- 设置缩放 -->
      <meta name="viewport" content="minimal-ui,width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
      <!-- IOS中禁用将数字识别为电话号码/忽略Android平台中对邮箱地址的识别 -->
      <meta name="format-detection" content="telephone=no" />
      <!-- windows phone 点击无高光 -->
      <meta name="msapplication-tap-highlight" content="no" />
      <!-- icon -->
      <link rel="shortcut icon" href="<?php echo ADMIN_ICO_PIC;?>" type="image/x-icon"/>
      <!-- css -->
      <link rel="stylesheet" type="text/css" href="<?php echo SYS_LINK;?>admin/css/content.css?v=<?php echo V_CSSJS;?>" />

      <style>
        body .sys_con_box{width:auto;min-width:auto;}
        body .sys_box{overflow:hidden;min-height:600px;}
        .db_backups,.db_recovery{float:left;width:460px;min-height:150px;margin-bottom:20px;border-right:1px solid #ddd;}
        .title{height:30px;line-height:30px;text-align:center;font-size:16px;font-weight:400;}
        .tableB{padding:5px 5px 5px 5px;text-align: center;}
        input[type="checkbox"]{margin-right:10px;}
        .sub_btn {padding: 6px 15px;background: #00BCD4;color: #fff;margin-top: 5px;}
        .still_input{width: 280px; height: 30px; border: 1px solid #ddd; padding: 0 10px;}
        .file_html{margin:20px;}
        .file_html .item{width:400px;margin: 5px 0 5px 0;overflow: hidden;color:#999;white-space:nowrap;}
      </style>
  </head>
<body class="noselect">
<?php
$userLevel = isset($userLevel) ? $userLevel : 0;
$powerInfo = isset($powerInfo) ? $powerInfo : powerInfoListDeVal();
?>
<div class="con_box">
    <!-- tab导航 -->
    <?php include SYS_PATH.SYS_APP_PATH.'/admin/views/admin_system/navtab.php';?>
	<!--  -->
	<div class="sys_con_box">
		<div class="sys_box ">
			<div class="db_backups">
				<div class="title">生成纯静态页面</div>
                <div class="tableB">
                    <input type="button" value="更新全部 ➜ " class="sub_btn" id="goStill">
                    <input type="button" value="更新栏目 ➜ " class="sub_btn" id="goStill2">
                </div>
                <div class="title">
                    <input type="text" class="still_input" id="still_url" placeholder="必须是域名后的连接">
                    <input type="button" value="生 成 ➜ " class="sub_btn still_btn_no" id="goStillNo">
                </div>
                <div class="file_html">
                    <div class="title"></div>
                    <div class="title">静态文件（<?php echo isset($fileArr) ? count($fileArr) : 0;?>）</div>
                    <div style="overflow: hidden;overflow-y: auto;height:400px;border:1px solid #ccc;padding:10px;">
                        <div>
                            <?php
                            foreach($fileArr as $v){
                                echo '<div class="item" title="'.$v.'">'.$v.'</div>'.PHP_EOL;
                            }
                            ?>
                        </div>
                    </div>
                </div>
			</div>
			<div class="db_recovery">
				<div class="title">清空纯静态文件</div>
				<div class="tableB">
                    <input type="button" value="清空所有 ≠" class="sub_btn" id="delStill">
				</div>
			</div>
		
		</div>
	</div>
</div>


</body>
<script language="javascript">
    var cssjsv = '<?php echo V_CSSJS;?>';
    var http_url = '<?php echo SYS_HOST;?>';
    var http_link = '<?php echo SYS_LINK;?>';
    var http_fix = '<?php echo SYS_URL_FIX;?>';
</script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/jquery.min.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/skin.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>admin/js/common.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript" src="<?php echo SYS_LINK;?>plug/common/function.js?v=<?php echo V_CSSJS;?>"></script>
<script type="text/javascript">file_load('info');</script>
<script language="javascript">
    // 页面加载完毕
    window.onload = function () {

    }

    var stillFlag = '<?php echo $stillFlag;?>';
    var delUrl = http_url+"admin_system_delstill"+http_fix;
    var oneStillUrl = http_url+"admin_system_setonestill";
    // 静态清空
    $("#delStill").click(function(){
        if(stillFlag != 1){
            layer.msg('请先开启纯静态开关');return false;
        }
        layer.confirm('确定清空静态缓存文件？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            layer.closeAll();
            var indexLoad = layer.load(1, {shade: [0.8,'#333']});
            $.post(delUrl,{},function(data){
                if(data == 'Y'){
                    layer.msg('操作成功');
                }else{
                    layer.msg('操作失败');
                }
                setTimeout(function(){
                    layer.close(indexLoad);
                    window.location.reload();
                    },2000);
            },'json').error(function(){
                layer.msg('操作异常');
                setTimeout(function(){
                    layer.close(indexLoad);
                    window.location.reload();
                },2000);
            });
        }, function(){    });
    });

    // 更新单个
    $('#goStillNo').click(function(){
        var still_url = $('#still_url').val();
        if(stillFlag != 1){
            layer.msg('请先开启纯静态开关');return false;
        }
        if(!still_url){
            layer.msg('未指定链接');return false;
        }else if(still_url.indexOf(http_url) != -1){
            layer.msg('不能包含域名部分');return false;
        }
        layer.load(1, {shade: [0.8,'#333']});
        $.post(oneStillUrl+http_fix,{urlname:still_url},function(res){
            layer.closeAll();
            if(res.code == 10000){
                layer.msg('执行成功');
            }else{
                layer.msg('执行失败');
            }
            window.location.reload();
        },'json').error(function(e){
            layer.closeAll();
            layer.msg('失败！稍后再试');
        });
        //window.location.href = oneStillUrl+"/urlname/"+encodeURIComponent(still_url)+http_fix;
    })



    // 加载标识
    var loadFlag = 1;

    // 执行方法
    function goFun(flag, operate){
        $.post('<?php echo SYS_URL_PATH("admin_system_setstill")?>',{
            flag:flag,
            operate:operate
        },function(res){
            if(res.code == 10000){
                loadFlag == 1;
                layer.msg('执行已完成');
                setTimeout(function(){
                    window.location.reload();
                },2000);
            }else if(res.code == 10001){
                loadFlag == 2;
                layer.msg('正在执行中……,已完成 <font color="#11e1fb" size="3">'+res.rate+' %</font>')
            }else{
                loadFlag == 1;
                layer.msg('失败！稍后再试');
            }
            var regPos = /^[0-9]+.?[0-9]*/; //判断是否是数字。
            if(!regPos.test(res.rate) ){
                loadFlag == 1;
                window.location.reload();
            }
        },'json').error(function(e){
            loadFlag == 1;
            layer.msg('失败！稍后再试');
        });
    }

    // 刷新进度
    function reloadRate(flag){
        setInterval(function(){
            console.log('1');
            if(loadFlag == 2){ goFun(flag, 2);}
        }, 3000);
    }

    // 更新所有栏目
    $('#goStill2').click(function(){
        var still_url = $('#still_url').val();
        if(stillFlag != 1){
            layer.msg('请先开启纯静态开关');return false;
        }
        //layer.load(1, {shade: [0.8,'#333']});

        if(loadFlag != 1){
            layer.msg('正在执行……');return false;
        }
        layer.confirm('确定更新所有栏目？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            layer.closeAll();
            loadFlag = 2;
            let flag = 'menus';
            goFun(flag, 1);
            reloadRate(flag);
        }, function(){

        });

        //window.location.href = stillUrl+'/flag/menus'+http_fix;
    })

    // 更新全部
    $('#goStill').click(function(){
        var still_url = $('#still_url').val();
        if(stillFlag != 1){
            layer.msg('请先开启纯静态开关');return false;
        }
        if(loadFlag != 1){
            layer.msg('正在执行……');return false;
        }
        layer.confirm('确定更新全部？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            layer.closeAll();
            loadFlag = 2;
            let flag = 'all';
            goFun(flag, 1);
            reloadRate(flag);
        }, function(){

        });
    })

</script>
</html>